package com.tencent.wxcloudrun.service;

import com.alibaba.fastjson2.JSON;
import com.tencent.wxcloudrun.dao.ConfigMapper;
import com.tencent.wxcloudrun.model.Config;
import com.tencent.wxcloudrun.model.RechargeMoney;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: ConfigService
 * Package: com.tencent.wxcloudrun.service
 * Description:
 *
 * @Date: 2023/1/23 2:04 PM
 * @Author: wht
 */
@Slf4j
@Service
public class ConfigService {
    @Autowired
    ConfigMapper configMapper;

    public void addOneConfig(Config config) {
        config.setRecharge_money_json(JSON.toJSONString(config.getRecharge_money()));
        config.setActivity_list_json(JSON.toJSONString(config.getActivity_list()));
        configMapper.addOneConfig(config);
    }

    public void updateOneConfigById(Config config) {
        config.setRecharge_money_json(JSON.toJSONString(config.getRecharge_money()));
        config.setActivity_list_json(JSON.toJSONString(config.getActivity_list()));
        configMapper.updateOneConfigById(config);
    }

    public List<Config> getConfigListAll() {
        List<Config> configList = configMapper.getConfigListAll();
        for (Config config1 : configList) {
            config1.setRecharge_money(JSON.parseArray(config1.getRecharge_money_json(), RechargeMoney.class));
            config1.setActivity_list(JSON.parseArray(config1.getActivity_list_json()));
        }
        return configList;
    }
}
